<?php
//author:zhuting
//function:post/read/delete dynamics
//表：动态(用户id，时间，内容，得分，打分人数，阅读量)
//功能：发表动态、删除动态、敏感词过滤、插件 
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Session;
use app\index\model\Dynamics as Dyn;

class Dynamics extends Controller
{
	//验证登陆
	/*function _initialize()
	{
		if( !Session::has('phone') ) {
			$this->error('请先登录！', url('admin/Login/login'));
		}
	}*/
	
	 public function test(Request $request){
		$dyn = new Dyn;
	    	$count = $dyn
	    					
	    					->count();
	    	$this->assign('count',$theme);
    }
	//渲染显示页面
	public function index(){
		
		$theme = "王羲之书法作品";
		$date =  date('Y-m-d H:i:s', time());
		$number = 2333;
		$score = 80;
		$txt = "给大家展示一副王羲之的书法作品。";
		
		$this->assign('theme',$theme);
		$this->assign('time',$date);
		$this->assign('number',$number);
		$this->assign('score',$score);
		$this->assign('txt',$txt);
		return $this->fetch('dynamic');
		
	}
	
	//发表动态页面显示
    public function post(){
    	$this->assign('theme','请输入主题.......');//初始化控件
    	return $this->fetch('new_dynamic');
    }
    
    //发表动态写入数据库
    public function add(Request $request){
    	$theme = $request->param("theme");
		$txt = $request->param("txt");
		
		//echo $theme;
		//echo $txt;
		
		$dyn = new Dyn;
		$dyn->theme = $theme;
		$dyn->user_id = "2";
//		$dyn->ptime = "1";
		$dyn->content = $txt;
		$dyn->read_num = "1";
		$dyn->score_num = "1";
		$dyn->score = "1";
//		$dyn->ptime = date("Y-M-D");
		$dyn->save();
		return json(0);
//		echo "<script type='text/javascript'>alert('发表完成！');parent.location.href='../../index/dynamics/post';</script>";
    	
    }
    
    //删除动态
    public function delete(){
    	
    }
    
    //敏感词过滤
    public function check(){
    	
    	
    }

	//跳转阅读
	public function dynamics()
	{
		
	}
}
?>
